package editor.cn;
class Solution2414{
    public static void main(String[] args) {
        Solution solution = new Solution2414().new Solution();
        String str="abcde";
        System.out.println("str = " + solution.longestContinuousSubstring(str));
    }


    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int longestContinuousSubstring(String s) {
    //    最长子串有一套标准逻辑的，记得吗？标准公式。kadenx's公司来着，就两行代码贼秒。
    //    StringBuilder maxSub=new StringBuilder(s.charAt(0));
        StringBuilder maxSub=new StringBuilder().append(s.charAt(0));
        StringBuilder currentSub=new StringBuilder().append(s.charAt(0));
        int n=s.length();
        int maxSubLen=1;
        for (int i = 1; i < n; i++) {
            char ch=s.charAt(i);
            if (isContinue(currentSub.append(ch))){
                maxSubLen=Math.max(currentSub.length(),maxSubLen);
            }else {
                currentSub.replace(0,currentSub.length(), String.valueOf(ch));
            }
        }
        return maxSubLen;
    }

        private boolean isContinue(StringBuilder currentSub) {
            int n=currentSub.length();
            for (int i = 1; i < n; i++) {
                if ((currentSub.charAt(i)-'0')-(currentSub.charAt(i-1)-'0')!=1){
                    return false;
                }
            }
            return true;
    }
    }
//leetcode submit region end(Prohibit modification and deletion)

}












